﻿$(document).ready(function () {

    var mydate = new Date();
    var year = mydate.getFullYear();
    var month = mydate.getMonth() + 1;
    GetCelandar(year, month, "1");
    GetRecommend(year, month, "1");



    $("#searchlistcity a").click(function () {
        city_dw = $(this).attr("id");
        loadCityName(city_dw);
        $("#searchlistcity").hide(500);
        //		$('#h2citych').html($(this).html());
    })
    
    loadCityName(cid);
    //$("#m").toggle(function(){$("#searchlistcity").show();},function(){$("#searchlistcity").hide();})

    $("#city_index").click(function (event) {
        if ($("#searchlistcity").css('display') == 'block') {
            $("#searchlistcity").fadeOut("slow");
            event.stopPropagation();
        }
        else {
            $("#searchlistcity").fadeIn("slow");
            event.stopPropagation();
            $(document).unbind('click').click(function (event) {
                $("#searchlistcity").hide(500);
            });
        }
    });

    $("#searchlistcity").hover(function () {
        $(document).unbind('click');
    }, function () {
        $(document).click(function (event) {
            $("#searchlistcity").hide(500);
        });
    });


});
function GetCelandar(year, month, city){
    var src = "/xmldata/Celandar/Calender" + year + "_" + month + "_1.html";
    $("#spyear").html(year);
    $("#strmonth").html(month);
    $("#CalenderFrame").attr("src", src);
    var aaa = EnglistMonth(month);
    $("#emonth").html(aaa);
}

function GetRecommend(year, month, city){
    var src = "/xmldata/Celandar/IndexRecommend" + year + "_" + month + "_1.html";
    $("#RecommendFrame").attr("src", src);
    $("#remonth").html(month);
}

function ChangeCelander(stype){
    var year = parseInt($("#spyear").html());
    var month = parseInt($("#strmonth").html(month));
    var nmonth;
    var nyear;
    if (stype == "1") {
        nmonth = month + 1;
        if (nmonth == 13) {
            nmonth = 1;
            nyear = year + 1;
        }
        else {
            nyear = year;
        }
    }
    else {
        nmonth = month - 1;
        nyear = year;
         if(month==11)
            {
                nyear=nyear-1;
            }
        if (nmonth == 0) {
            nmonth = 12;
            nyear=year-1
            
        }
    }
    
    var src = "Calender" + nyear + "_" + nmonth + "_1.html";
    var url1 = '/ajaxcms/ajax_getCelander.ashx?filename=' + escape(src);
    $.ajax({
        type: 'GET',
        url: url1,
        success: function(msg){
            //alert(msg);
            if (msg != 1) {
                        GetCelandar(year,month,"1");
                        GetRecommend(year,month,"1");
            }
            else {
                GetCelandar(nyear, nmonth, "1");
                GetRecommend(nyear, nmonth, "1");
            }
        }
    })
}

function loadCityName(cityidliu) {
    //alert("abcd=" + cityidliu);
    var city_wang;
    $("#searchlistcity a").each(function () {
        //alert("abcd=" + cityidliu);
        var spanid = $(this).attr("id");
        
        if (spanid == cityidliu) {
            cityname_wang = $(this).text();
            $("#city_index").text(cityname_wang);
            
            loadHotFilms(spanid);
        }
    });
}

//加载首页指定城市Id的正在上映影片
function loadHotFilms(cityidliu) {
    //alert("abc=" + cityidliu);
    var src = "/xmldata/bingdianhtml/hotFilmByC_HP/" + cityidliu + ".html";
    alert(src);
    $("#hot").load(src);
}

function EnglistMonth(month){
    var em = "";
    switch (month) {
        case 1:
            em = "January";
            break;
        case 2:
            em = "February";
            break;
        case 3:
            em = "March";
            break;
        case 4:
            em = "April";
            break;
        case 5:
            em = "May";
            break;
        case 6:
            em = "June";
            break;
        case 7:
            em = "July";
            break;
        case 8:
            em = "August";
            break;
        case 9:
            em = "September";
            break;
        case 10:
            em = "October";
            break;
        case 11:
            em = "November";
            break;
        case 12:
            em = "December";
            break;
        default:
            em = "";
    }
    return em;
}